<?php 
/**
 * eBay Label Printing Program Email handler
 * This is the Email handler, It read the correspond email template and send to Website user Emails 
 * @package  eBayLabelPrinter
 * @category Model
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 * @static PATH_EMAIL_TEMPLATE email template folder Location
 * @staticvar string $sginUpSuccessTemp template Name for sign Up success Email
 * @staticvar string $signUpSuccessSubject  Email subject for Sign up Success Email
 */

define ("PATH_EMAIL_TEMPLATE", '/admin/template/email/');
class Model_Handlers_Emailhandler
{
	//not decide Yet
	//const PATH_EMAIL_TEMPLATE = '/admin/template/email/';
	private static $signUpSuccessTemp = 'signupsuccess.tmp';
	private static $signUpSuccessSubject = 'Sign Up  Success on Shipping Label Maker';
	
	private static $forgetPasswordTemp = 'forgetpassword.tmp';
	private static $forgetPasswordSubject = 'Reset Your Password at Shipping Label Maker';
	
	private static $upgradeSuccessTemp = 'upgradesuccess.tmp';
	private static $upgradeSucdessSubject = 'Upgrade Success on Shipping Label Maker';
	
	private static $passwordResetSuccessTemp = 'passwordresetsuccess.tmp';
	private static $passwordResetSuccessSubject = 'Password Rest Success on Shipping Label Maker';
	
	private static $defaultSenderEmail = 'noreply@shippinglabelmaker.com';
	private static $defaultSenderName = 'Shipping Label Maker Customer Support';
	
	//private static $vocherAcceptTemp = '.tmp'; Not finish Yet	
	
	/**
	 * This is Send SignUp Email Function,send email after successfully build the seller Account and Add Seller address
	 * @param string $userNameSeller
	 * @param string $userEmailSeller
	 * @param string $passwordSeller
	 * @param string $unzipPassword
	 * @param string $userGroupSeller This one Must need change 
	 * @return boolean   send Email Success Or Not
	 */
	
	public function sendSignUpEmail($userNameSeller,$userEmailSeller,$passwordSeller,$unzipPassword,$userGroupSeller){
		$emailContent = self::readTemplate($signUpSuccessTemp);
		if($emailContent){
			//replace what should be in there
			$emailContent = str_replace('[username_seller]',$userNameSeller,$emailContent);
			$emailContent = str_replace('[group_seller]',$userGroupSeller,$emailContent);
			$emailContent = str_replace('[password_seller]',$passwordSeller,$emailContent);
			$emailContent = str_replace('[unzip_password]',$unzipPassword,$emailContent);
			//replace Done,send it out
			self::sendTheEmail($userEmailSeller, $emailContent,$signUpSuccessSubject);			
		}
		else{
			return false;
		}	
		
		return true;
	}
	public function sendChangePasswordEmail(){
		
	}
	public function sendUpgradeSuccessEmail(){
		
	}
	public function sendVocherSuccessEmail(){
		
	}
	public function passwordResetSuccessEmail(){
		
	}
	public function vocherAcceptEmail(){
		
	}
	public function sendErrorEmail(){
		
	}
	/**
	 * This is Send Email Function, it actually going to send the email out after 
	 * other program modify and update necessary information
	 * @param string $receiverEmail
	 * @param string $emailContent
	 * @param string $emailSubject
	 * @return voide 
	 */
	public function sendTheEmail($receiverEmail,$emailContent,$emailSubject){

		$mail = new Zend_Mail();
		$mail->setFrom($defaultSenderEmail,$defaultSenderName);
		$mail->setBodyHtml($emailContent);
		$mail->addTo($receiverEmail,$receiverEmail);
		$mail->setSubject($emailSubject);
		$mail->send();
				
	}
	/**
	 * This is Read Template Function, read correspond Html template for defined folder and return the HTML string 
	 * @param string $templateName
	 * @return string  Will return the email content, return false while read fail
	 */	
	public function readTemplate($templateName){
		try{
		$fs = fopen(PATH_EMAIL_TEMPLATE.$templateName,"r");
		$emailContent = fread($fs,filesize(PATH_EMAIL_TEMPLATE.$templateName));
		}
		catch(Exception $e){
			
			return false;
		}
		return $emailContent;
		
	}
}
?>